<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<script>
/**
 *    注意： 此组件为修改条码信息的公共diglog组件
 */



 /**
  * 根据条码查询/修改条码详情
  */
 function viewBarcodeDetails(barcode){
 	 $('#dlg').dialog('open');
 	 var params = 'formBean.barcode='+barcode;
 	 $.post("action/productJSONAction!barcodeInfoData",params,selectBarcodeBackProcessS,"json");
 }
  
 function selectBarcodeBackProcessS(date){
 	//dig的所有ID前缀为：dig_
 	//注意: 修改条码diglog中的品牌输入框使用的是singleBrandInput.jsp 组件（单选品牌，不支持多选）
 	//console.log(date.rows);
 	
 	var rows = date.rows;
 	var product = rows.product;
 	var brand = rows.product.brand;
 	 $("#single_brandName").textbox('setValue',brand.brand_Name);
      $("#single_brand_ID").val(brand.brand_ID);
      
      $("#viewImgBarcode").val(rows.barcode);
      $("#dig_productId").val(product.productId);
      $("#dig_productBarcodeId").val(rows.id);
      $("#brandName").textbox('setValue',brand.brand_Name);
      $("#dig_productCode").textbox('setValue',product.productCode);
      $("#dig_serialNum").textbox('setValue',product.serialNum);

      if(brand.belong_To == 0){
     	 $("#dig_belongTo").textbox('setValue',"千禧");
      }else if(brand.belong_To == 1){
     	 $("#dig_belongTo").textbox('setValue',"禧乐仓");
      }else if(brand.belong_To == 2){
     	 $("#dig_belongTo").textbox('setValue',"店铺");
      }else if(brand.belong_To == 3){
     	 $("#dig_belongTo").textbox('setValue',"其他");
      }
      $("#dig_barcode").textbox('setValue',rows.barcode);
      
      $("#dig_factoryCode").textbox('setValue',product.factoryCode);
      $("#dig_productIdentity").textbox('setValue',product.productIdentity);
      
      $("#dig_colorId").combobox('setValue',rows.color.colorId);
      $("#dig_yearId").combobox('setValue',product.year.year_ID);
      $("#dig_quarterId").combobox('setValue',product.quarter.quarter_ID);
      $("#dig_categoryLevelId").combobox('setValue',product.categoryLevel1.category_ID);
      $("#dig_categoryId").combobox('setValue',product.category.category_ID);
      $("#dig_numPerHand").combobox('setValue',product.numPerHand);
      $("#dig_unit").combobox('setValue',product.unit);
      $("#dig_sizeMin").combobox('setValue',product.sizeMin);
      $("#dig_sizeMax").combobox('setValue',product.sizeMax);
      
      $("#dig_salesPrice").textbox('setValue',product.salesPrice);
      $("#dig_recCost").textbox('setValue',product.recCost);
      $("#dig_costMultiple").textbox('setValue',product.costMultiple);
      $("#dig_discount").textbox('setValue',product.discount);
      $("#dig_wholeSalePrice").textbox('setValue',product.wholeSalePrice);
      $("#dig_wholeSalePrice2").textbox('setValue',product.wholeSalePrice2);
      $("#dig_wholeSalePrice3").textbox('setValue',product.wholeSalePrice3);
      $("#dig_salesPriceFactory").textbox('setValue',product.salesPriceFactory);
      $("#dig_material").textbox('setValue',product.material);
      
 }

 /**
  * 修改条码
  */
 function update(){
 	var error ="";
 	if ($("#dig_productCode").val() == ""){
 		error +="产品货号 - 不能为空\n";
 		$("#dig_productCode").focus();
 	} 	
 	
 	if ($("#brand_ID").val() == ""){
 		error +="产品牌 - 不能为空\n";
 	} 	
 	var categoryLevelId = $("#dig_categoryLevelId").combo("getValue");
 	if (categoryLevelId != "0" && !isValidPositiveInteger(categoryLevelId)){
 		$.messager.alert('错误', '产品线类型不是一个正确的输入', 'warning');
 		return;
 	}

 	var categoryId = $("#dig_categoryId").combo("getValue");
 	if (categoryId != "0" && !isValidPositiveInteger(categoryId)){
 		$.messager.alert('错误', '货品类别不是一个正确的输入', 'warning');
 		return;
 	}
 	
 	var colorId = $("#dig_colorId").combo("getValue");
 	if (!isValidPositiveInteger(categoryId)){
 		$.messager.alert('错误', '颜色不是一个正确的输入', 'warning');
 		return;
 	}
 	
 	var priceValue = $("#dig_salesPrice").val();
 	if (priceValue != "" && isNaN(priceValue)){
         error += "连锁店零售价 - 必须是数字\n";
         $("#dig_salesPrice").focus();
 	} else if (priceValue != "" && priceValue == 0){
         $("#dig_salesPrice").val("");
 	} 
 	
 	var costMultiple = $("#dig_costMultiple").val();
 	if (costMultiple != "" && isNaN(costMultiple)){
         error += "成本倍数 - 必须是数字\n";
         $("#dig_costMultiple").focus();
 	} else if (costMultiple != "" && costMultiple == 0){
         $("#dig_costMultiple").val("");
 	}

 	var recCostValue = $("#dig_recCost").val();
 	if (recCostValue != "" && isNaN(recCostValue)){
         error += "进价 - 必须是数字\n";
         $("#dig_recCost").focus();
 	} else if (recCostValue != "" && recCostValue == 0){
         $("#dig_recCost").val("");
 	} 
 	
 	var wholePriceValue = $("#dig_wholeSalePrice").val();
 	if (wholePriceValue != "" && isNaN(wholePriceValue)){
         error += "预设价1 - 必须是数字\n";
         $("#dig_wholeSalePrice").focus();
 	} else if (wholePriceValue != "" && wholePriceValue == 0){
         $("#dig_wholeSalePrice").val("");
 	} 

 	var wholePriceValue2 = $("#dig_wholeSalePrice2").val();
 	if (wholePriceValue2 != "" && isNaN(wholePriceValue2)){
         error += "预设价2 - 必须是数字\n";
         $("#dig_wholeSalePrice2").focus();
 	} else if (wholePriceValue2 != "" && wholePriceValue2 == 0){
         $("#dig_wholeSalePrice2").val("");
 	} 

 	var wholePriceValue3 = $("#dig_wholeSalePrice3").val();
 	if (wholePriceValue3 != "" && isNaN(wholePriceValue3)){
         error += "预设价3 - 必须是数字\n";
         $("#dig_wholeSalePrice3").focus();
 	} else if (wholePriceValue3 != "" && wholePriceValue3 == 0){
         $("#dig_wholeSalePrice3").val("");
 	} 

 	var salesPriceFactoryValue = $("#dig_salesPriceFactory").val();
 	if (salesPriceFactoryValue != "" && isNaN(salesPriceFactoryValue)){
         error += "厂家零售价 - 必须是数字\n";
         $("#dig_salesPriceFactory").focus();
 	} else if (salesPriceFactoryValue != "" && salesPriceFactoryValue == 0){
         $("#dig_salesPriceFactory").val("");
 	} 

 	var discountValue = $("#dig_discount").val();
 	if (discountValue != "" && isNaN(discountValue)){
         error += "折扣 - 必须是数字\n";
         $("#dig_discount").focus();
 	} else if (discountValue != "" && (discountValue < 0 || discountValue >1)){
         error += "折扣 - 必须是小于或者等于1的正数\n";
         $("#dig_discount").focus();
 	} else if (discountValue != "" && discountValue == 0){
         $("#dig_discount").val("");
 	} 
 	
 	if (error != "")
 	    $.messager.alert('错误', error, 'warning');
 	else {
 		var params = $.serializeObject($('#barcodeEditForm'));
 		$.post("action/productJSONAction!updateBarcode",params,updateBarcodeBackProcessS,"json");
 	}
 }

 function updateBarcodeBackProcessS(date){
 	$('#dlg').dialog('close')
 	if(date.success){
 		$.messager.alert('提示', date.message, 'info');
 	}else{
 		$.messager.alert('错误', date.message, 'error');
 	}
 }

 /**
  * 删除条码
  */
 function deleteBarcode(){
 	var info = "你确定删除此商品条码信息?\n此商品信息一经删除所有相关单据都将删除对应信息!";
 	if (confirm(info)){
 	    var params=$("#updateProductForm").serialize();  
 	    $.post("action/productJSONAction!checkBarcode",params, backProcess,"json");
 	} 
 }
 function backProcess(data){
 	var result = data.result;
 	if (result == false){
 	  var params = $.serializeObject($('#barcodeEditForm'));
 	  $.post("action/productJSONAction!deleteBarcode",params,deleteBarcodeBackProcessS,"json");
 	  
 	} else {
 	  $.messager.alert('错误', '此条码已经使用无法删除', 'warning');
 	}
 }

 function deleteBarcodeBackProcessS(date){
 	$('#dlg').dialog('close')
 	if(date.success){
 		$.messager.alert('提示', date.message, 'info');
 	}else{
 		$.messager.alert('错误', date.message, 'error');
 	}
 }
 
 
 /**
 * 查看图片
 */
 function viewImgByDiglog(){
		var params = $.serializeObject($('#barcodeEditForm'));
		var barcode = params.barcode;

		if(barcode != null && barcode != ""){
			$.modalDialog({
				title : '平面图片详情',
				width : 410,
				height : 570,
				modal : false,
				href : 'commonJSPAction!viewImg?formBean.barcode='
						+ barcode,
				buttons : [ {
					text : '关闭窗口',
					handler : function() {
						$.modalDialog.handler.dialog('close');
					}
				} ]
			});
		}else{
		    $.messager.alert('提示','该条码暂无图片信息','warning');
		}
		
	}
</script>
		 <div id="dlg" class="easyui-dialog" title="修改条码" data-options="iconCls:'icon-edit',buttons: [{
                    text:'确认',
                    iconCls:'icon-ok',
                    handler:function(){                        
                        update();
                    }
                },{
                    text:'删除',
                    iconCls:'icon-no',
                    handler:function(){
                        deleteBarcode();
                    }
                },{
                    text:'取消',
                    iconCls:'icon-undo',
                    handler:function(){
                        $('#dlg').dialog('close')
                    }
                }]" style="width:80%;height:550px;max-width:1350px;padding:10px">
		        
		        <s:form id="barcodeEditForm" name="barcodeEditForm" action="" method="POST" theme="simple">			    
				<table  class="OuterTable" width="100%"  style=" border-collapse: collapse;border-bottom: 1px solid #e5e5e5;">
				<tr style=" border: 2px solid #e5e5e5; ">
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>品牌：</strong></span></td>
					<td width="17%" ><%@ include file="../common/SingleBrandInput.jsp"%></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>产品货号：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_productCode" name="formBean.productBarcode.product.productCode"  data-options="prompt:'请输入产品货号'"   style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>颜色：</strong></span></td>
					<td width="17%"><s:select name="formBean.productBarcode.color.colorId"
									cssClass="easyui-combobox" style="width:200px" data-options="prompt:'请选择货品颜色'" 
									size="1" id="dig_colorId" list="uiBean.basicData.colorList"
									listKey="colorId" listValue="name" headerKey="" headerValue=""/></td>
					<td width="8%" height="55" align="center"><strong>厂家货号：</strong></td>
					<td width="17%">
						 <input class="easyui-textbox" id="dig_factoryCode" name="formBean.productBarcode.product.factoryCode"  data-options="prompt:'请输入厂家货号'"   style="width:200px" >
						 <input type="hidden" name="formBean.productBarcode.product.productId" id="dig_productId"/>
						 <input type="hidden" name="formBean.productBarcode.id" id="dig_productBarcodeId"/>
						 <input type="hidden" name="barcode" id="viewImgBarcode">
					</td>			
				</tr>
				<tr style=" border: 2px solid #e5e5e5; ">
					<td width="8%" height="55" align="center" align="center"><span><strong>商品归属：</strong></span></td>
					<td width="17%" ><input class="easyui-textbox" data-options="prompt:'商品归属',readonly:true" id="dig_belongTo"  style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span><strong>商品编码：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_serialNum" data-options="prompt:'商品编码',readonly:true" name="formBean.productBarcode.product.serialNum"  style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span><strong>条形码：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_barcode" data-options="prompt:'条形码',readonly:true" name="formBean.productBarcode.barcode" style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span><strong>公司货号：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_productIdentity" data-options="prompt:'公司货号',readonly:true" name="formBean.productBarcode.product.productIdentity" style="width:200px" ></td>			
				</tr>
				<tr style=" border: 2px solid #e5e5e5; ">
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>年份：</strong></span></td>
					<td width="17%" ><s:select  cssClass="easyui-combobox" style="width:200px;height:32px;text-align: center"
								name="formBean.productBarcode.product.year.year_ID" size="1"
								id="dig_yearId" list="uiBean.basicData.yearList" listKey="year_ID"
								data-options="prompt:'请选择年份'"
								listValue="year" headerKey="0" headerValue="" /></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>季度：</strong></span></td>
					<td width="17%"><s:select  cssClass="easyui-combobox" style="width:200px;height:32px;text-align: center"
								name="formBean.productBarcode.product.quarter.quarter_ID"
								size="1" id="dig_quarterId" list="uiBean.basicData.quarterList"
								listKey="quarter_ID" listValue="quarter_Name" headerKey="0"
								data-options="prompt:'季度'"
								headerValue="" /></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>产品线：</strong></span></td>
					<td width="17%"><s:select  style="width:200px;height:32px;text-align: center"
 								name="formBean.productBarcode.product.categoryLevel1.category_ID"
								size="1" cssClass="easyui-combobox" id="dig_categoryLevelId"
								data-options="prompt:'产品线'"								
								list="uiBean.basicData.categoryLevelList" listKey="category_ID"
								listValue="category_Name" headerKey="0" headerValue="" /></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>货品类别：</strong></span></td>
					<td width="17%"><s:select  style="width:200px;height:32px;text-align: center"
								name="formBean.productBarcode.product.category.category_ID"
								size="1" cssClass="easyui-combobox" id="dig_categoryId"
								data-options="prompt:'货品类'"
								list="uiBean.basicData.categoryList" listKey="category_ID"
								listValue="category_Name" headerKey="0" headerValue="" /></td>			
				</tr>
				<tr style=" border: 2px solid #e5e5e5; ">
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>齐码数量：</strong></span></td>
					<td width="17%" ><s:select style="width:200px;height:32px;text-align: center" data-options="prompt:'请选择齐码数量'" 
									name="formBean.productBarcode.product.numPerHand" size="1" cssClass="easyui-combobox"
									id="dig_numPerHand" list="uiBean.basicData.numPerHandList"
									listKey="numPerHand" listValue="numPerHand"  headerKey="0" headerValue=""/></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>单位：</strong></span></td>
					<td width="17%"><s:select name="formBean.productBarcode.product.unit" 
									style="width:200px;height:32px;text-align: center"  cssClass="easyui-combobox"
									size="1" id="dig_unit" list="uiBean.basicData.unitList"
									data-options="prompt:'请选择单位'" 
									listKey="productUnit" listValue="productUnit" headerKey="0" headerValue="" /></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>最小码：</strong></span></td>
					<td width="17%"><s:select cssClass="easyui-combobox"
					style="width:200px;height:32px;text-align: center" data-options="prompt:'请选择最小码'" 
					 name="formBean.productBarcode.product.sizeMin"  id="dig_sizeMin"
					  list="#{'60':'60','70':'70','80':'80','90':'90','100':'100','110':'110','120':'120','130':'130','140':'140','150':'150','160':'160','170':'170'}" listKey="key" listValue="value" headerKey="0" headerValue="" /></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>最大码：</strong></span></td>
					<td width="17%"><s:select   cssClass="easyui-combobox"
					style="width:200px;height:32px;text-align: center" id="dig_sizeMax"
					name="formBean.productBarcode.product.sizeMax"  data-options="prompt:'请选择最大码'" 
					 list="#{'110':'110','120':'120','130':'130','140':'140','150':'150','160':'160','170':'170','180':'180','190':'190'}" listKey="key" listValue="value" headerKey="0" headerValue="" /></td>			
				</tr>
				
				<tr style=" border: 2px solid #e5e5e5; ">
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>千禧吊牌价：</strong></span></td>
					<td width="17%" ><input class="easyui-textbox" id="dig_salesPrice" name="formBean.productBarcode.product.salesPrice" data-options="prompt:'请输入千禧吊牌价'"  style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>进价：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_recCost" name="formBean.productBarcode.product.recCost" id="recCost"  data-options="prompt:'请输入进价'" style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>成本倍数：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_costMultiple" name="formBean.productBarcode.product.costMultiple" data-options="prompt:'请输入成本倍数'"  style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>折扣：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_discount" name="formBean.productBarcode.product.discount" data-options="prompt:'请输入折扣'" style="width:200px" ></td>			
				</tr>
				<tr style=" border: 2px solid #e5e5e5; ">
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>预设价1：</strong></span></td>
					<td width="17%" ><input class="easyui-textbox" id="dig_wholeSalePrice" name="formBean.productBarcode.product.wholeSalePrice" data-options="prompt:'请输入预设价1'" style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>预设价2：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_wholeSalePrice2" name="formBean.productBarcode.product.wholeSalePrice2" data-options="prompt:'请输入预设价2'" style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>预设价3：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_wholeSalePrice3" name="formBean.productBarcode.product.wholeSalePrice3" data-options="prompt:'请输入预设价3'" style="width:200px" ></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>厂家零售价：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_salesPriceFactory" name="formBean.productBarcode.product.salesPriceFactory" data-options="prompt:'请输入厂家零售价'" style="width:200px" ></td>			
				</tr>
				<tr style=" border: 2px solid #e5e5e5; ">
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>面料：</strong></span></td>
					<td width="17%"><input class="easyui-textbox" id="dig_material"  name="formBean.productBarcode.product.material" style="width:200px" data-options="prompt:'请输入货品面料信息'" ></td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>图片上传：</strong></span></td>
					<td width="17%">
						<input class="easyui-filebox" id="inventory"   data-options="prompt:'请选择图片文件',buttonText: '文件',buttonAlign: 'left'" style="width:100%">			
					</td>
					<td width="8%" height="55" align="center"><span style="color:red;"><strong>*</strong></span><span><strong>图片详情：</strong></span></td>
					<td width="17%">
						<a onclick="viewImgByDiglog();" href="javascript:void(0);"  style="height:25px;">查看图片</a>						
					</td>
					<td></td>
					<td></td>								
				</tr>
				
				</table>	
				</s:form>
		  </div>